package com.celesea.auth.role.vo;

import com.celesea.auth.menu.vo.MenuTreeVo;
import com.celesea.auth.role.entity.Role;
import com.celesea.auth.role.entity.RolePermission;
import com.celesea.auth.role.v1.controller.request.RolePermissionRequest;
import com.google.common.collect.Lists;

import java.util.List;

public class RolePermissionVo {
    private String id;
    private String code;
    private String name;
    private List<String> permissions;
    private List<MenuTreeVo> permissionTrees;

    public RolePermissionVo(String id, RolePermissionRequest request) {
        this.id=id;
        this.permissions=request.getPermissions();
    }

    public RolePermissionVo(Role entity) {
        this.id=entity.getId();
        this.code=entity.getCode();
        this.name=entity.getName();
    }

    public List<RolePermission> toPermissionVo() {
        List<RolePermission> result= Lists.newArrayList();
        permissions.forEach(code->result.add(new RolePermission(this.id,code)));
        return result;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }

    public List<MenuTreeVo> getPermissionTrees() {
        return permissionTrees;
    }

    public void setPermissionTrees(List<MenuTreeVo> permissionTrees) {
        this.permissionTrees = permissionTrees;
    }
}
